import json

with open("疫情.txt", "r", encoding="utf-8") as f:
    data = f.read()
data = json.loads(data)
print(type(data), data)
data = data["areaTree"][0]["children"]
data_list = []
data_list2 = []
print(data, type(data))
for e in data:
    e_name = e["name"]
    e_value = e["total"]["confirm"]
    data_list.append([e_name, e_value])
print("12", data_list)
province_abbreviation_to_full_name = {
    "台湾": "台湾省",
    "江苏": "江苏省",
    "云南": "云南省",
    "河南": "河南省",
    "上海": "上海市",
    "湖南": "湖南省",
    "湖北": "湖北省",
    "广东": "广东省",
    "香港": "香港特别行政区",
    "福建": "福建省",
    "浙江": "浙江省",
    "山东": "山东省",
    "四川": "四川省",
    "天津": "天津市",
    "北京": "北京市",
    "陕西": "陕西省",
    "广西": "广西壮族自治区",
    "辽宁": "辽宁省",
    "重庆": "重庆市",
    "澳门": "澳门特别行政区",
    "甘肃": "甘肃省",
    "山西": "山西省",
    "海南": "海南省",
    "内蒙古": "内蒙古自治区",
    "吉林": "吉林省",
    "黑龙江": "黑龙江省",
    "宁夏": "宁夏回族自治区",
    "青海": "青海省",
    "江西": "江西省",
    "贵州": "贵州省",
    "西藏": "西藏自治区",
    "安徽": "安徽省",
    "河北": "河北省",
    "新疆": "新疆维吾尔自治区"
}
for data in data_list:
    new_name = province_abbreviation_to_full_name[data[0]]
    data[0] = new_name
    data_list2.append(data)
print(data_list2)
new_data = json.dumps(data_list2, ensure_ascii=False)
print(type(new_data), new_data)
with open("各个省份疫情.txt", "w", encoding="utf-8") as f:
    f.write(new_data)
    f.flush()